<?php
	session_start();
	require("user_type/member.php");
	include("user_type/system.php");
	$userID = intval($_SESSION['ID']);
	
	if(isset($_POST['artbtn'])){ //Upload articles
		$filename = "articles/".$_FILES['articlename']["name"];
		$filetype = "art";
		$private = $_POST['private'];
		$artkw1 = $_POST['artkw1'];
		$artkw2 = $_POST['artkw2'];
		$artkw3 = $_POST['artkw3'];
		$artTitle = $_POST['arttitle'];
		if(Member::uploadFile($filename, $filetype, $artTitle,$userID, $private, $artkw1, $artkw2, $artkw3)==-1){
			echo "You File have Unacceptable or stopword. 0.2 point will be reduced form your credits";
			System::reduceCredits($userID);
			echo "<br> <a href=\"home.php\">Go to Home Page</a> <br><a href=\"uploadForm.php\">Upload More Files</a>";
			exit();
			}
		echo "Your article has been uploaded. Thank You.  <br> <a href=\"home.php\">Go to Home Page</a> <br><a href=\"uploadForm.php\">Upload More Files</a>";
		}
	elseif(isset($_POST['imgbtn'])){//Upload images
		$filename = "images/".$_FILES['imagename']["name"];
		$filetype = "img";
		$private = $_POST['private'];
		$imgkw1 = $_POST['imgkw1']; 	if (empty($imgkw1)) $imgkw1 = NULL;
		$imgkw2 = $_POST['imgkw2'];
		$imgkw3 = $_POST['imgkw3'];
		$imgTitle = $_POST['imgtitle'];
		Member::uploadFile($filename, $filetype, $imgTitle, $userID, $private, $imgkw1, $imgkw2, $imgkw3);
		echo "Your image has been uploaded. Thank You.  <br> <a href=home.php>Go to Home Page</a><br><a href=\"uploadForm.php\">Upload More Files</a>";
		
		// move image to 'images folder'
		$file = fopen($filename, 'w');
		fclose($file);
		move_uploaded_file($_FILES['imagename']['tmp_name'], "$filename/");
		
		}
	else{
		//$_SESSION['error'] = 'Invalid File Type. Please check your file type and try again. ';
	}	
?>